package net.pinnoocle.playshoppc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.page.PageModel;
import net.pinnoocle.playdao.entity.shopPc.user.*;
import net.pinnoocle.playdao.entity.web.user.UserCouponListPageVo;
import net.pinnoocle.playdao.entity.web.user.UserCouponListSearchParams;
import net.pinnoocle.playdao.entity.web.user.UserScriptListPageVo;
import net.pinnoocle.playservice.service.impl.CouponServiceImpl;
import net.pinnoocle.playservice.service.impl.OrderServiceImpl;
import net.pinnoocle.playservice.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ye
 * @Description
 * @create 2021-10-25 17:00
 */

@RestController
@RequestMapping("/user")
@Api(tags = "会员管理")
public class UserController {

    @Autowired
    UserServiceImpl userService;
    @Autowired
    OrderServiceImpl orderService;
    @Autowired
    CouponServiceImpl couponService;

    @GetMapping("shopUserList")
    @ApiOperation("店铺会员列表")
    public BaseResult<PageModel<UserListPageVo>> shopUserList(UserListSearchParams params){
        return new BaseResult<PageModel<UserListPageVo>>().ok(userService.shopUserList(params));
    }

    @GetMapping("shopUserLevelList")
    @ApiOperation("店铺会员等级列表")
    public BaseResult<List<UserLevelListVo>> shopUserLevelList(){
        return new BaseResult<List<UserLevelListVo>>().ok(userService.userLevelList());
    }

    @PostMapping("editUserLevel")
    @ApiOperation("会员等级编辑")
    public BaseResult<String> editUserLevel(@Validated @RequestBody SaveUserLevelParams params){
        boolean result = userService.editUserLevel(params);
        if(result){
            return new BaseResult<String>().success("会员等级编辑成功");
        }
        return new BaseResult<String>().error("会员等级编辑失败");
    }

    @GetMapping("deleteLevel")
    @ApiOperation("删除会员级别")
    public BaseResult<String> deleteLevel(@RequestParam("levelId") String levelId){
        boolean result = userService.deleteUserLevel(levelId);
        if(result){
            return new BaseResult<String>().success("删除会员级别成功");
        }
        return new BaseResult<String>().error("删除会员级别失败");
    }

    @GetMapping("userPlayScripts")
    @ApiOperation("用户玩过的本")
    public BaseResult<PageModel<UserScriptListPageVo>> myScripts(@RequestParam("userId") String userId,
                                                                 @RequestParam("page") Integer page,
                                                                 @RequestParam("pageSize") Integer pageSize){
        return new BaseResult<PageModel<UserScriptListPageVo>>().ok(userService.myScripts(userId,page,pageSize,0));
    }

    @GetMapping("setUserMemberLevel")
    @ApiOperation("设置用户会员级别")
    public BaseResult<String> setUserMemberLevel(@RequestParam("userId") String userId,
                                                 @RequestParam("memberLevelId") Integer memberLevelId){
        boolean result = userService.setUserMemberLevel(userId, memberLevelId);
        if(result){
            return new BaseResult<String>().success("会员等级设置成功");
        }
        return new BaseResult<String>().error("会员等级设置失败");
    }

    @GetMapping("startPayToUser")
    @ApiOperation("向指定玩家发起收款")
    public BaseResult<String> startPayToUser(@RequestParam("userId") String userId,@RequestParam("payPrice") Double payPrice){
        boolean result = orderService.startPayToUserForPc(userId,payPrice);
        if(result){
            return new BaseResult<String>().success("发起收款成功");
        }
        return new BaseResult<String>().error("发起收款失败");
    }

    @GetMapping("userCouponList")
    @ApiOperation("用户优惠券列表")
    public BaseResult<PageModel<UserCouponListPageVo>> userCouponList(UserCouponListSearchParams params){
        return new BaseResult<PageModel<UserCouponListPageVo>>().ok(couponService.userCouponList(params));
    }

}
